package com.example.demo.service.impl;

import com.example.demo.mapper.ClazzMapper;
import com.example.demo.pojo.Clazz;
import com.example.demo.pojo.ClazzQueryParam;
import com.example.demo.pojo.PageResult;
import com.example.demo.service.ClazzService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class ClazzServiceImpl implements ClazzService {
@Autowired
   private ClazzMapper clazzMapper;

    @Override
    public PageResult page(ClazzQueryParam clazzQueryParam) {


        PageHelper.startPage(clazzQueryParam.getPage(),clazzQueryParam.getPageSize());

        Page<Clazz> p= clazzMapper.list(clazzQueryParam);
        return new PageResult(p.getTotal(),p.getResult());
    }

    @Override
    public void delete(Integer id) {

        clazzMapper.delete(id);

    }

    @Override
    public void save(Clazz clazz) {

        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());


        clazzMapper.save(clazz);
    }

    @Override
    public Clazz find(Integer id ) {
        return clazzMapper.find(id);
    }

    @Override
    public void update(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.update(clazz);
    }

    @Override
    public List<Clazz> findall() {

        return clazzMapper.findall();
    }
}
